from time import sleep
from selenium import webdriver


driver = webdriver.Chrome()
driver.maximize_window()
url = "http://192.168.1.238/index.php/Home/user/login.html"
driver.get(url)
driver.implicitly_wait(10)


driver.find_element_by_id('username').send_keys('13800138006')
driver.find_element_by_id('password').send_keys('123456')
driver.find_element_by_id('verify_code').send_keys('1111')
driver.find_element_by_name('sbtbutton').click()

# 个人信息
driver.find_element_by_link_text('个人信息').click()
sleep(2)

attr_src_value1 = driver.find_element_by_id('preview').get_attribute('src')

driver.find_element_by_id('preview').click()
sleep(2)
frame = driver.find_element_by_id('layui-layer-iframe1')
driver.switch_to.frame(frame)
driver.find_element_by_css_selector('[id=filePicker] div:nth-child(2) > input').send_keys(r'C:\Users\Administrator\Desktop\M.jpg')
sleep(2)
driver.find_element_by_class_name('saveBtn').click()
sleep(2)
attr_src_value2 = driver.find_element_by_id('preview').get_attribute('src')

if attr_src_value1 != attr_src_value2 :
    print('PASS,头像修改成功')
else:
    print('FAIL,头像修改失败')

driver.switch_to.default_content()

# 商品搜索 加入购物车

driver.find_element_by_id('q').send_keys('手机')
driver.find_element_by_link_text('搜索').click()

ele = driver.find_element_by_link_text('综合')
# 0 None 空集合    为False ,  其它都为True
if ele:
    print('PASS,搜索成功')
else:
    print("FAIL,搜索失败")
driver.find_element_by_xpath('//*[@class="clearfix p"]//a[1]').click()
sleep(2)
driver.find_element_by_css_selector('[class="u-av-label"]').click()
sleep(2)

driver.find_element_by_xpath('//*[contains(text(),"【套餐赠耳机】HUAWEI/华为 畅享8 Plus")]').click()

driver.find_element_by_id('join_cart').click()
frame = driver.find_element_by_id('layui-layer-iframe1')
driver.switch_to.frame(frame)
buy_success_text = driver.find_element_by_css_selector('[class="conect-title"] span:first-child').text

if buy_success_text == "添加成功":
    print("PASS,购物车添加成功")
else:
    print('Fail,购物车添加失败')

driver.find_element_by_link_text('继续购物').click()
driver.switch_to.default_content()

# 新增收货地址


